from termcolor import colored
import datetime
from Settings import LOG_FILE

class Console():
    def write_log(self,msg):
        log=open(LOG_FILE,'a')
        log.write(msg+"\n")
        log.close()
    
    
    
    def warning(self, msg):
        date=datetime.datetime.today().strftime("%Y/%m/%d %H:%M:%S")
        print(colored(f"{date}:",'grey',on_color="on_white")+colored(f"Warning:",'yellow')+msg)
        if LOG_FILE!="":
            self.write_log((f"{date}:"+f"Warning:"+msg))
    def error(self, msg):
        date=datetime.datetime.today().strftime("%Y/%m/%d %H:%M:%S")
        print(colored(f"{date}:",'grey',on_color="on_white")+colored(f"Error:",'red')+msg)
        if LOG_FILE!="":
            self.write_log((f"{date}:"+f"Error:"+msg))
    def info(self, msg):
        date=datetime.datetime.today().strftime("%Y/%m/%d %H:%M:%S")
        print(colored(f"{date}:",'grey',on_color="on_white")+colored(f"Info:",'cyan')+msg)
        if LOG_FILE!="":
            self.write_log((f"{date}:"+f"Info:"+msg))
console=Console()